<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
   

  </head>
  
  <body>
    <div class="easyui-layout" fit="true">
		<!-- 表格上的toolbar工具条 -->
		<div id="easyui_toolbar" region="north" border="true" style="border-bottom:1px solid #999;height:32px;">
			<div style="height:5px; width:100%;"></div>
			<div style="height:10px;width:620px;float:left;"></div>
        	<input class="easyui-searchbox" data-options="prompt:'请输入查询条件...',menu:'#mm',searcher:activitytable" style="width:300px"></input>
			<div id="mm">
				<div data-options="name:'acdescribe',iconCls:'icon-ok'">活动内容模糊查找</div>
				<div data-options="name:'acid'">活动编号精确查找</div>
				<div data-options="name:'actime'">开始、结束时间模糊查找</div>
			</div>
			<font color="red" style="position:absolute;top:5px; left:5px;">登录页大图只能显示前三项</font>
        	
		</div>
		<!-- 表格数据区域 -->
		
		<div region="center" border="false" data-optinos:"fit:true;" style="">
			<table id="activitytable">
			
			</table>
		</div>
	</div>
	
	<!-- 活动大图站展示与切换 -->
	<div id="acphotodialog" class="easyui-dialog" title="活动大图" style="width:300px; height:300px;"
			data-options="iconCls:'pag-list',modal:true,closable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true">
		<div style="margin-left:5px;margin-right:5px;margin-top:5px;">
			<form name="acphotoform">
				<input type="hidden" id="acid" name="acid" value=""/>
				<table style="margin-top:20px; margin-left:20px;margin-right:20px;vertical-align:middle;" width="80%" border="0" cellpadding="0" cellspacing="1">
					<tr>
						<td style="width:20%; text-align:center;">
							<div id="imgdiv">
								<img id="acphoto" name="acphoto" width="220" height="123"/>
							</div>
						</td>	
					</tr>
					<tr>
						<td>
							<br/>
							<input type="file" name="up_img" id="up_img"/>
						</td>
					</tr>
				</table>
			</form>
			<div style="text-align:right;margin-right:30px;">
				<a href="javascript:updateAcphoto()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a>
				<a href="javascript:yhj_cancel('acphotodialog')" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">取消</a>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	
		function updateAcphoto(){
			if($("#up_img").val()==""){
				//alert("不能插入空图片");
				showinfobox(1,"","不能插入空图片");
				return ;
			}
			$.ajaxFileUpload({
				url:"backadmin/file.action",//这个action主要用来接收上传的文件
				secureuri:false,//上传的时候是否使用安全协议https而不用http
				type:"POST",
				dataType:"JSON",
				fileElementId:"up_img",//上传文件域的id
				data:{op:'acphoto',acid:$("#acid").val(),addrDir:'/activityphotos'},
				success:function(data){
					if(data!=""){
						//$("#acphotodialog").window("close");
						yhj_cancel('acphotodialog');
						//$('#UimageDialog').datagrid('load'); 
						searchactivity("","");
						showinfobox(1,"","修改成功...");
					}else{
						//失败了
						showinfobox(1,"","修改失败...");
					}
				}
			});
		}
		
		function yhj_cancel(name){
			$("#uimage").removeAttr("src");
			$("#up_img").val("");
			$("#acphotodialog").window("close");
		}
		function changeAcphoto(acid,acphoto){
			//alert(uid+"\t"+uimage);
			//1,0001.jpg
			new uploadPreview({ UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "acphoto" });
			if(acphoto!="acphoto"||acphoto!=""){
				$("#acphoto").attr("src","images/mixedPicData/"+acphoto);
			}else{
				$("#acphoto").attr("src","images/yhj_upload.png");
			}
			$("#acid").val(acid);
			$("#acphotodialog").window("open");
		}
	
	
	
		function searchactivity(value,name){
			$("#activitytable").edatagrid({
				url:"backadmin/actives.action?op=findallactivity",
			    saveUrl: "backadmin/actives.action?op=addactivity",
			    updateUrl: "backadmin/actives.action?op=updateactivity",
			    idField:"acid",
				pagination:true,
				pageNumber:1,
				pageSize:10,
				pageList:[10,20,30,40,50],
				fit:true,
				rownumbers:true,
				sortName:"acid",
				title:"活动信息表",
				sortOrder:"desc",
				fitColumns:true,
				singleSelect:true,
				queryParams:{
					fname:value
				},
				columns:[[
					{field:"acid",title:"活动编号",width:100,align:"center"},
					{field:"acname",title:"活动名称",width:100,align:"center",editor:'text'},
					{field:"acstatus",title:"活动状态",width:100,align:"center",editor:'text',
						formatter:function(value){
							if(value==0){
								return "<font color='red'>已禁用\\0</font>";
							}else{
								return "<font color='green'>已开启\\1</font>";
							}
						}	
					},
					{field:"acdiscount",title:"活动折扣率",width:100,align:"center",editor:'text'},
					{field:"acstarttime",title:"活动开始时间",width:100,align:"center",editor:'text'},
					{field:"acendtime",title:"活动结束时间",width:100,align:"center",editor:'text'},
					{field:"acphoto",title:"活动海报",width:100,align:"center",
						formatter: function(value,rec){
		        			return '<img class="editCls1" src="images/mixedPicData/'+value+'" width="90" height="90" href="javascript:void(0)" onclick="changeAcphoto(\''+rec.acid+'\',\''+value+'\')"/>';
		        	 	 }
					},
					{field:"acdescribe",title:"活动描述",width:100,align:"center",editor:'text'}
				]],
				onLoadSuccess:function(data){
					//linkbuttonAdjust();
					$("#activitytable").edatagrid("fitColumns");//修复不对齐的bug
					changeStatus();
				},
				onAfterEdit:function(data){//编辑后修改linkbutton
					
				},
				toolbar:[
				         {
				        	 iconCls:'icon-add',
				        	 text:"添加",
				        	 handler:function(){
				        		 $("#activitytable").edatagrid('addRow');
				        	 }
				         },{
				        	 iconCls:'icon-save',
				        	 text:"保存",
				        	 handler:function(){
				        		 $("#activitytable").edatagrid('saveRow');//完成添加或更新
				        	 }
				         },{
				        	 iconCls:'icon-undo',
				        	 text:"取消编辑",
				        	 handler:function(){
				        		 $("#activitytable").edatagrid('cancelRow');
				        	 }
				  		  }
				  ]
			});
		}
		
		$(function(){
			searchactivity(null,null);
			new uploadPreview({ UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "uimage" });

		});
			
	</script>
  </body>
</html>
